package com.AntiThesis.atmodtx2;

import electroblob.wizardry.spell.Mine;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;

import java.util.HashMap;
import java.util.List;
import java.util.Random;

public class LineEffect {
    static Random random = new Random();
    HashMap<String, String> map = new HashMap();

    public void skill(String[] s) {
        for (int i = 0; i < s.length; i++) {
            map.put("value" + i, s[i]);
        }
        castskill(map);

    }
    private void castskill(HashMap<String, String> map) {
        double x = Double.parseDouble(map.get("value0"));
        double y = Double.parseDouble(map.get("value1"));
        double z = Double.parseDouble(map.get("value2"));
        double area = Double.parseDouble(map.get("value3"));
        String particleType = (map.get("value4"));
        World world = Minecraft.getMinecraft().player.world;
        double x2 = Double.parseDouble(map.get("value5"));
        double y2 = Double.parseDouble(map.get("value6"));
        double z2 = Double.parseDouble(map.get("value7"));
        double xyzanglestart = Double.parseDouble(map.get("value8"));
        double speed = Double.parseDouble(map.get("value9"));
        double amount = Double.parseDouble(map.get("value10"));
        String castuid = map.get("value11");
        String xadd = map.get("value12");
        String yadd = map.get("value13");
        String zadd = map.get("value14");
        Entity player = null;
        List<Entity> loadedEntityList = Minecraft.getMinecraft().world.getLoadedEntityList();
        for (Entity entity : loadedEntityList) {
            if (entity.getUniqueID().toString().equals(castuid)){
                player=entity;
            }
        }
        Minecraft.getMinecraft().addScheduledTask(() -> {
        Vec3d pos1 = new Vec3d(x,y,z);
        Vec3d pos2 = new Vec3d(x2,y2,z2);
        double v = pos1.distanceTo(pos2);

        Vec3d normalize = pos1.subtract(pos2).normalize();
        if (!xadd.equals("0")||!yadd.equals("0")||!zadd.equals("0")){
        for (double i =0;i<v;i+=0.27){

            pos1 = pos1.add(new Vec3d(normalize.x*0.27,normalize.y*0.27,normalize.z*0.27));
            for (int i2 = 0;i2<amount;i2++){

                world.spawnParticle(EnumParticleTypes.valueOf(particleType),pos1.x+(random.nextDouble()*area-(area/2)),pos1.y+(random.nextDouble()*area-(area/2)),pos1.z+(random.nextDouble()*area-(area/2)),Double.parseDouble(xadd)*speed ,Double.parseDouble(yadd)*speed,Double.parseDouble(zadd)*speed);

                }

        }
        }
        else {
            for(double i =0;i<v;i+=0.27){
                pos1 = pos1.add(new Vec3d(normalize.x*0.27,normalize.y*0.27,normalize.z*0.27));
                for (int i2 = 0;i2<amount;i2++){
                world.spawnParticle(EnumParticleTypes.valueOf(particleType),pos1.x+(random.nextDouble()*area-(area/2)),pos1.y+(random.nextDouble()*area-(area/2)),pos1.z+(random.nextDouble()*area-(area/2)),random.nextDouble()*speed ,random.nextDouble()*speed,random.nextDouble()*speed);
            }
            }
        }});

    }



}